package com.aaa.controller;

import com.aaa.entity.User;
import com.aaa.service.UserService;
import com.aaa.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 荆豪峰
 * @version 1.0
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户模块说明")
@CrossOrigin(origins = "*",allowedHeaders = "*")
public class UserController {
   @Autowired
    private UserService userService;
    @PostMapping("/delete")
    @ApiOperation(value = "用户信息删除")
    @ApiImplicitParams({@ApiImplicitParam(name="id",value = "用户id",required = true,dataType = "int",paramType = "query")})
    public Result delete(Integer id){
        return   userService.delete(id);
    }


    @PostMapping("/add")
    @ApiOperation(value="用户信息添加")
    public Result add(@RequestBody User user){
        return userService.add(user);
    }

    @RequestMapping("/update")
    @ApiOperation(value="用户信息更新")
    public Result update(@RequestBody User user){
        System.out.println(user);
        return userService.update(user);
    }

    @GetMapping("/select")
    @ApiOperation(value = "查询用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name="currentPage",value="当前页",required=true,dataType="int",paramType="query"),
            @ApiImplicitParam(name="pageSize",value="每页几条数据",required=true,dataType="int",paramType="query")
    })
    public Result selectAll(@RequestParam(defaultValue = "1")Integer currentPage,@RequestParam(defaultValue = "5") Integer pageSize){
        return userService.SelectAll(currentPage, pageSize);
    }
    @GetMapping("/list")
    public Result list(){
        return userService.list();
    }
    @PostMapping("/login")
    public Result login(@RequestBody User user){
        return userService.findByNameAndPass(user.getUsername(),user.getPassword());
    }
}
